package com.jt.demo23.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Order(value = 1)
public class DemoAspect {
    @Pointcut("bean(personServiceImpl)")
    public void pointCut(){
    }

//    public void qian(){
//        long l = System.currentTimeMillis();
//    }
//    public void huo(){
//        DemoAspect demoAspect = new DemoAspect();
//
//        long l1 = System.currentTimeMillis();
//    }

    @Around("pointCut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        long l = System.currentTimeMillis();
        System.out.println("环绕前");
        Object proceed = point.proceed();
        System.out.println("环绕后");
        long l1 = System.currentTimeMillis();
        System.out.println(l1-l);
        return proceed;
    }

    @AfterThrowing(value = "execution(* com.jt.demo23.Service..*.*(..))",throwing = "exception")
    public void afterthrow(Exception exception){
        System.out.println(exception.getMessage());
    }

}
